package  com.rrs.cost.record.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.rk.core.auth.util.SecurityUtil;
import org.rk.core.common.util.RkObjectUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import  com.rrs.cost.record.CostRecord;
@Controller
@RequestMapping("/rk/admin/rrs/cost/record/")
public class CostRecordAdmin extends CostRecordWeb {
	@RequiresPermissions(value="costRecord:save")
	@RequestMapping(value = "save", method = RequestMethod.POST)
	public @ResponseBody Object save(CostRecord costRecord) {
		if(RkObjectUtil.isEmpty(costRecord.getId())){
			costRecord.setCreator(SecurityUtil.getUserName());
			getCostRecordService().insertModel(costRecord);
		}else{
			costRecord.setUpdator(SecurityUtil.getUserName());
			getCostRecordService().updateCalcModel(costRecord);
		}
		return ajaxSucc("保存成功");
	}

	@RequiresPermissions(value="costRecord:delete")
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	public @ResponseBody Object delete(@RequestParam("idArr[]") List<Long> idArr) {
		for (Long id : idArr) {
			getCostRecordService().deleteById(id);
		}
		return ajaxSucc("删除成功");
	}
	@RequiresPermissions(value="costRecord:submitVerify")
	@RequestMapping(value = "submitVerify", method = RequestMethod.POST)
	public @ResponseBody Object submitVerify(@RequestParam("idArr[]") List<Long> idArr) {
		//业务部门提交》使用部门审核中
		for (Long id : idArr) {
			getCostRecordService().verify(id,"1");
		}
		return ajaxSucc("提交成功");
	}
	@RequiresPermissions(value="costRecord:useDepVerify")
	@RequestMapping(value = "useDepVerify", method = RequestMethod.POST)
	public @ResponseBody Object useDepVerify(@RequestParam("idArr[]") List<Long> idArr,String yesOrNo) {
		//使用部门审核》管理部门审核中
		for (Long id : idArr) {
			if("1".equals(yesOrNo)) {
				getCostRecordService().verify(id,"2");
			}else {
				getCostRecordService().verify(id,"0");
			}
		}
		return ajaxSucc("提交成功");
	}
	@RequiresPermissions(value="costRecord:manageDepVerify")
	@RequestMapping(value = "manageDepVerify", method = RequestMethod.POST)
	public @ResponseBody Object manageDepVerify(@RequestParam("idArr[]") List<Long> idArr,String yesOrNo) {
		//管理部门审核》主管部门审核中
		for (Long id : idArr) {
			if("1".equals(yesOrNo)) {
				getCostRecordService().verify(id,"3");
			}else {
				getCostRecordService().verify(id,"0");
			}
		}
		return ajaxSucc("提交成功");
	}
	@RequiresPermissions(value="costRecord:mainDepVerify")
	@RequestMapping(value = "mainDepVerify", method = RequestMethod.POST)
	public @ResponseBody Object mainDepVerify(@RequestParam("idArr[]") List<Long> idArr,String yesOrNo) {
		//主管部门审核》结束
		for (Long id : idArr) {
			if("1".equals(yesOrNo)) {
				getCostRecordService().verify(id,"9");
			}else {
				getCostRecordService().verify(id,"0");
			}
		}
		return ajaxSucc("提交成功");
	}
}
